﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormTBK.Function
{
    public partial class MultiDoWork : Form
    {
        List<BackgroundWorker> bgWorkers = new List<BackgroundWorker>();
        public MultiDoWork()
        {
            InitializeComponent();
        }

        private void MultiDoWork_Load(object sender, EventArgs e)
        {
            this.t1.RowCount = 10;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            t1.GetType().GetProperty("DoubleBuffered",BindingFlags.Instance| BindingFlags.NonPublic).SetValue(t1, true, null);
            this.t1.RowCount = new Random().Next(20);
            t1.AutoSize = true;
            for (int i = 0; i < this.t1.RowCount; i++)
            {
                Label l = new Label();
                l.Text = "aaaaa" + i.ToString();
                this.t1.Controls.Add(l, 0, i);
                this.t1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute,36F));
            }
            return;
            if (string.IsNullOrWhiteSpace(this.tbThreadAmount.Text.Trim()))
            {
                MessageBox.Show(this, "请输入线程数量");
                return;
            }
            //根据线程分配资源
            int amount = 0;
            if (!int.TryParse(this.tbThreadAmount.Text.Trim(), out amount))
            {
                MessageBox.Show(this, "SB??");
            }
            if (amount <= 0)
            {
                MessageBox.Show(this, "SB??");
            }
            lib.DoWork dw = new lib.DoWork();
            for (int i = 0; i < amount; i++)
            {
                BackgroundWorker bgWorker=new BackgroundWorker();
                bgWorker.DoWork += dw.MultiDoWork_DoWork;
                bgWorker.ProgressChanged += dw.ProgressChanged;
                bgWorker.RunWorkerCompleted += dw.RunWorkerCompleted;
                bgWorker.Site.Name="bgWorker"+i;
                this.bgWorkers.Add(bgWorker);
                bgWorker.RunWorkerAsync("参数");
            }

        }
    }
}
